package com.travel.controller.tourist_demand;


import com.travel.common.ServerResponse;
import com.travel.pojo.tourist_demand.Address;
import com.travel.pojo.tourist_demand.TouristImage;
import com.travel.pojo.tourist_demand.TouristTrabelDemand;
import com.travel.service.tourist_demand.TouristTrabelDemandServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/touristTrabelDemand")
public class TouristTrabelDemandController {

    @Autowired
    TouristTrabelDemandServer trabelDemandServer;

    /**
     * 根据子活动地名查找团
     * @param addressname 子活动地名
     */
    @GetMapping("/queryAll/{addressname}")
    public ServerResponse<List<TouristTrabelDemand>> queryAll(@PathVariable("addressname") String addressname){
      return trabelDemandServer.queryTTlDemandByAddress(addressname);
    }

    /**
     * 根据入团码查团信息
     * @param code 入团码
     */
    @GetMapping("/queryInformationByCode/{code}")
    public ServerResponse<TouristTrabelDemand> queryInformationByCode(@PathVariable("code") int code){
        return trabelDemandServer.queryTTlDemandByCode(code);
    }

    /**
     * 根据团id查团
     * @param id 团id
     */
    @GetMapping("/queryInformationById/{id}")
    public ServerResponse<TouristTrabelDemand> queryInformationById(@PathVariable("id") int id){
        return trabelDemandServer.queryTTlDemandById(id);
    }

    /**
     * 发布团接口
     * @param id 用户(导游)id
     * @param trabelDemand 发布团信息
     */
    @PutMapping("/addInformation/{id}")
    @ResponseBody
    public ServerResponse<Map> addInformation(@PathVariable("id") int id, TouristTrabelDemand trabelDemand){
            return trabelDemandServer.addDemand(id,trabelDemand);
    }

    /**
     * 删除团接口
     * @param tid 团id
     */
    @GetMapping("/deleteTrabelDemand/{tid}")
    public ServerResponse<String> deleteTrabelDemand(@PathVariable("tid")int tid){
        return trabelDemandServer.deleteTrabelDemand(tid);
    }

    /**
     * 加入旅游团
     * @param userid 用户id
     * @param code 入团码
     */
    @GetMapping("/jionDemand/{userid}/{code}")
    public ServerResponse<TouristTrabelDemand> jionDemand(@PathVariable("userid") int userid,@PathVariable("code") int code){
            return trabelDemandServer.joinDemand(userid,code);
    }

    /**
     * 退出团
     * @param userid 用户id
     */
    @GetMapping("/singOutDemand/{userid}")
    public  ServerResponse<String> singOutDemand(@PathVariable("userid") int userid){
        return trabelDemandServer.singOutDemand(userid);
    }

    /**
     *添加旅游团子活动
     * @param address 旅游团子活动信息
     */
    @PostMapping("/addActivity")
    @ResponseBody
    public ServerResponse<Address> addActivity(Address address){
        System.out.println(address);
        return trabelDemandServer.addActivity(address);
    }

    /**
     *删除子活动
     * @param aid 子活动id
     */
    @GetMapping("/deleteActivity/{aid}")
    public ServerResponse<String> deleteActivity(@PathVariable("aid")int aid){
        return trabelDemandServer.deleteActivity(aid);
    }

    /**
     * 活动开始，更新子活动表中startcode为1
     * @param aid 子活动唯一id
     */
    @GetMapping("/startActivity/{aid}")
    public ServerResponse<String> startActivity(@PathVariable("aid") int aid){
        return trabelDemandServer.startActivity(aid);
    }

    /**
     *结束子活动 更新子活动表中startcode为2
     * @param aid 子活动唯一id
     */
    @GetMapping("/overActivity/{aid}")
    public ServerResponse<String> overActivity(@PathVariable("aid")int aid){
        return trabelDemandServer.overActivity(aid);
    }


    /**
     *开启签到 更新团信息中singin为1
     * @param tid 团数据id
     */
    @GetMapping("/startActivitySingin/{tid}")
    public ServerResponse<String> startActivitySingin(@PathVariable("tid") int tid){
       return trabelDemandServer.startSingin(tid);
    }

    /**
     *结束签到 更新团信息中singin为2
     * @param tid 团数据id
     */
    @GetMapping("/overActivitySingin/{tid}")
    public ServerResponse<String> overActivitySingin(@PathVariable("tid")int tid){
        return trabelDemandServer.overSingin(tid);
    }


    /**
     *用户集合签到 更新用户表中singin为2  表示已签到  1未签到，2已签到
     * @param id 用户唯一id
     */
    @GetMapping("/singinActivity/{id}")
    public ServerResponse<String> singinActivity(@PathVariable("id")int id){
        return trabelDemandServer.yesSingin(id);
    }


    /**
     *查团头图
     * @param cityName 团城市名
     */
    @GetMapping("/selectImage/{cityName}")
    public ServerResponse<TouristImage> selectImage(@PathVariable("cityName")String cityName){
       return trabelDemandServer.selectImageByCityName(cityName);
    }


}
